package com.dhwl.hsh.merchant.ui.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.dhwl.hsh.lib.bean.Address;
import com.dhwl.hsh.lib.utils.SystemTool;
import com.dhwl.hsh.merchant.R;
import com.dhwl.hsh.merchant.ui.activity.OrderDetailActivity;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 简要描述
 *
 * @author Derek.Kidd
 * @version V1.0.0
 * @date 2016-04-25 16:27
 */
public class ShipingAddressAdapter extends BaseAdapter<Address> {


    public ShipingAddressAdapter(Context context, List list) {
        super(context, list);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder;
        if (null == convertView) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_task_detail_address, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        final Address address = getList().get(position);

        if (!TextUtils.isEmpty(address.getPosiName())) {
            viewHolder.tvShippingAdd.setText(address.getPosiName());
        } else {
            viewHolder.tvShippingAdd.setText("");
        }
        viewHolder.imgShippingAdd.setTag(address.getLinkManMobile());

        viewHolder.imgShippingAdd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String tel = (String) v.getTag();
                SystemTool.call((OrderDetailActivity) context, tel);
            }
        });

        return convertView;
    }

    static class ViewHolder {

        /**
         * 配送地
         */
        @Bind(R.id.tv_shipping_address)
        TextView tvShippingAdd;
        /**
         * 配送地联系人电话
         */
        @Bind(R.id.img_task_detail_call)
        ImageView imgShippingAdd;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }

}
